<?php
/* 
	[BuyPg] (C) 2010-2011 Buypg
	$Id: WebpingAction.class.php 2011-4-26 10:32:43 wufujun $
 */

if (!defined('THINK_PATH')){
	exit('Access Denied');
}

class WebpingAction extends BpAction{
	
	public function index(){
		global $_SGLOBAL;
		//缓存
		if(S('webping_index')){
			$arrPrintClass = S('webping_index');
		}else{
			$DbClass = M('NbClass');
			$DbSite = M('NbSite');
			$arrClass = $DbClass->order('class_order desc')->select();
			foreach ($arrClass as $key=>$value){
				//查询当前分类下的15个网站
				$arrNbsite = array();
				$arrNbsite = $DbSite->where(' country_id = 0 and flag = 1 and class_id = '.$value['class_id'])->limit(15)->select();
				//格式化数据
				if($arrNbsite){
					foreach ($arrNbsite as $site_k => $site_v) {
						$arrNbsite[$site_k]['site_name'] = msubstr($site_v['site_name'], 0, 10, 'utf-8', FALSE);
					}
				}
				$value['site'] = $arrNbsite;
				$arrPrintClass[] = $value;
			}
			S('webping_index',$arrPrintClass,3600);
		}
		
		//定义右侧专题列表
		$RightZT = getRightZT();
		//模板输出
		$this->assign('classlist' , $arrPrintClass);
		$this->assign('rightzt' , $RightZT);
		$this->display();
	}

	public function webpingall(){
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		$classid = empty($_GET['classid']) ? 0 : intval($_GET['classid']) ;
		//默认以f1--网站易用排行
		$o = isset ($_GET['o']) ? $_GET['o'] : 'f1';
		if($classid){
			$DbSite = M('NbClass');
			$arrClass = $DbSite->where("class_id = $classid")->find();
			$DbSite = M('NbSite');
			$arrSite = $DbSite->where("class_id = $classid and flag = 1")->order("$o DESC")->select();
			if($arrSite){
				//格式化数据
				foreach ($arrSite as $key=>$value){
					$arrSite[$key]['site_name'] = 	msubstr($value['site_name'], 0, 10, 'utf-8', FALSE);
					$arrSite[$key][$o] = formatFen($value[$o]);
					if($arrSite[$key]['country_id'] == 0){
						$guoneiSite[] = $arrSite[$key];
					}else{
						$guowaiSite[] = $arrSite[$key];
					}
				}
			}else{
				$this->error('您查看的信息不存在或已经删除');
			}
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
		//定义左侧分类
		$LeftCate = getLeftCategory();

		//模板输出
		$this->assign('show_zhanti_menu' , 1); //左侧菜单显示专题
		$this->assign('o' , $o);
		$this->assign('leftcate' , $LeftCate);
		$this->assign('descmenu' , $pgsys['sys_webping_desc']); //排序菜单
		$this->assign('classinfo' , $arrClass);
		$this->assign('guonei' , $guoneiSite);
		$this->assign('guowai' , $guowaiSite);
		$this->display();
	}
	
	public function webpaiming(){
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		$classid = empty($_GET['classid']) ? 0 : intval($_GET['classid']) ;
		$flagid = empty ($_GET['flagid']) ? 0 : intval($_GET['flagid']);
		//默认以f1--网站易用排行
		$o = isset ($_GET['o']) ? $_GET['o'] : 'f1';
		if($classid){
			$DbSite = M('NbClass');
			$arrClass = $DbSite->where("class_id = $classid")->find();
			$DbSite = M('NbSite');
			$arrSite = $DbSite->where("class_id = $classid and flag = 1")->order("$o DESC")->select();
			if($arrSite){
				//格式化数据
				foreach ($arrSite as $key=>$value){
					$arrSite[$key]['site_name'] = 	msubstr($value['site_name'], 0, 10, 'utf-8', FALSE);
					$arrSite[$key][$o] = formatFen($value[$o]);
					if($arrSite[$key]['country_id'] == 0){
						$guoneiSite[] = $arrSite[$key];
					}else{
						$guowaiSite[] = $arrSite[$key];
					}
				}
			}else{
				$this->error('您查看的信息不存在或已经删除');
			}
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
		//定义左侧分类
		$LeftCate = getLeftCategory();

		//模板输出
		$this->assign('show_zhanti_menu' , 1); //左侧菜单显示专题
		$this->assign('o' , $o);
		$this->assign('flagid' , $flagid);
		$this->assign('leftcate' , $LeftCate);
		$this->assign('descmenu' , $pgsys['sys_webping_desc']); //排序菜单
		$this->assign('classinfo' , $arrClass);
		$this->assign('guonei' , $guoneiSite);
		$this->assign('guowai' , $guowaiSite);
		$this->display();
	}

	public function webpinglist(){
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		$classid = empty($_GET['classid']) ? 0 : intval($_GET['classid']) ;
		//默认以f1--网站易用排行
		$o = isset ($_GET['o']) ? $_GET['o'] : 'f1';
		if($classid){
			$DbSite = M('NbClass');
			$arrClass = $DbSite->where("class_id = $classid")->find();
			$DbSite = M('NbSite');
			import("@.ORG.Page"); //导入分页类
			$count = $DbSite->where("class_id = $classid and flag = 1")->count();    //计算总数
			$p = new Page ( $count, 20 );
			$arrSite = $DbSite->where("class_id = $classid and flag = 1")->limit($p->firstRow.','.$p->listRows)->order("country_id ASC , $o DESC")->select();

			$p->setConfig('header','篇记录');
			$p->setConfig('prev','<');
			$p->setConfig('next','>');
			$p->setConfig('first','<<');
			$p->setConfig('last','>>');

			$p->setConfig('theme', ' <span>%totalRow% %header% %nowPage%/%totalPage% 页 </span> %first% %upPage% %linkPage% %downPage% %end%');
			$page = $p->show(1);
			if($arrSite){
				//格式化数据
				foreach ($arrSite as $key=>$value){
					$arrSite[$key]['site_link'] = urldecode($value['site_link']);
					$arrSite[$key]['f1'] = formatFen($value['f1']);
					$arrSite[$key]['f2'] = formatFen($value['f2']);
					$arrSite[$key]['f3'] = formatFen($value['f3']);
					$arrSite[$key]['f4'] = formatFen($value['f4']);
					$arrSite[$key]['f5'] = formatFen($value['f5']);
					$arrSite[$key]['f6'] = formatFen($value['f6']);
					$arrSite[$key]['f7'] = formatFen($value['f7']);
				}
				$list = $arrSite;
			}else{
				$this->error('您查看的信息不存在或已经删除');
			}
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
		//定义左侧分类
		$LeftCate = getLeftCategory();

		//模板输出
		$this->assign('show_zhanti_menu' , 1); //左侧菜单显示专题
		$this->assign('o' , $o);
		$this->assign('leftcate' , $LeftCate);
		$this->assign('descmenu' , $pgsys['sys_webping_desc']); //排序菜单
		$this->assign('classinfo' , $arrClass);
		$this->assign('list' , $list);
		$this->assign('page' , $page);
		$this->display();
	}

	public function website(){
		global $_SGLOBAL;
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
		if($siteid){
			$DbSite = D('NbSite');
			$bigClassId = getBigClass($siteid);
			$resultSite = $DbSite->getSite("site_id = $siteid and flag = 1");
			if(!$resultSite){
				$this->error('您查看的信息不存在或已经删除');
			}else{
				//判断是否被认领
				$DbBiz = M("Biz");
				$arrBiz = $DbBiz->where("site_id = $siteid and site_flag = 1")->find();
				$isRl = 0;
				if($arrBiz){
					$isRl = 1;
				}
				//获取投诉分类与统计投诉数
				$DbTouSuClass = M('TousuClass');
				$arrTouSuClass = $DbTouSuClass->order("class_order desc")->select();
				$DbTouSu = M('NbTousu');
				//当前site的投诉总数
				$TouSuAmount = $DbTouSu->where("site_id = $siteid")->count();
				//当前site每个投诉分类的投诉数
				foreach($arrTouSuClass as $key => $value){
					 $arrTouSuClass[$key]['sum'] = $DbTouSu->where("site_id = $siteid and class_id = ".$value['class_id'])->count();
				}
				//获取评论
				$DbCommend= M("NbCommend");
				$arrCommend = $DbCommend->where("site_id = $siteid")->order("commend_dt desc")->limit(10)->select();
			}
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
		//定义左侧分类
		$LeftCate = getLeftCategory();
		
		//获取alexa
		$arrAlexa = array();
		$arrAlexa = GetAlexa(urldecode($resultSite['site_link']),$resultSite['site_id']);
		
		//获取回头率
		$DbSiteHt = M("SiteHt");
		$DbNbHt = M("NbHt");
		
		//更多评价&更多投诉
		$moreSearch = "http://www.baidu.com/s?wd=";
		$morePingJia = $moreSearch . urlencode(iconv("UTF-8","GB2312",$resultSite['site_name']." 　　　　　　　　 　　　　　　　　　　　　　　　　　　评价"));
		$moreTouSu = $moreSearch . urlencode(iconv("UTF-8","GB2312",$resultSite['site_name']." 　　　　　　　　 　　　　　　　　　　　　　　　　　　投诉"));
		
		$arrSiteHt = $DbSiteHt->where("site_id = $siteid")->find();
		if($arrSiteHt){
			$Htl = round($arrSiteHt['ht1'] / ($arrSiteHt['ht1'] + $arrSiteHt['ht2']),2) * 100; 
		}else{
			$Ht1 = $DbNbHt->where("site_id = $siteid and ht = 1")->count();
			$HtSum = $DbNbHt->where("site_id = $siteid")->count();
			$Htl = round(($Ht1 / $HtSum) , 2) * 100 ;
		}
		
		//seo相关设置
		$seotitle = "{$resultSite['site_name']},{$resultSite['site_name']}评价,{$resultSite['site_name']}投诉,{$resultSite['site_name']}购物,{$resultSite['site_name']}介绍,{$resultSite['site_name']}怎么样,{$resultSite['site_name']}好不好,{$resultSite['site_name']}优惠信息,{$resultSite['site_name']}团购信息,{$resultSite['site_name']}网站使用,{$resultSite['site_name']}商品质量,{$resultSite['site_name']}性价比, {$resultSite['site_name']}送货,{$resultSite['site_name']}售后服务,{$resultSite['site_name']}信誉,{$resultSite['site_name']}新闻";
		$seodescription = "百评网是中国最大的网上购 物评价和投诉的平台,提供 {$resultSite['site_name']}评价,{$resultSite['site_name']}投诉,{$resultSite['site_name']}购物信息,{$resultSite['site_name']}怎么样,{$resultSite['site_name']}好不好,{$resultSite['site_name']}优惠信息和{$resultSite['site_name']}团购信息,{$resultSite['site_name']}新闻。{$resultSite['site_name']}经营范围:{$resultSite['site_desc']}";
		$seokeywords = "{$resultSite['site_name']},{$resultSite['site_name']}评价,{$resultSite['site_name']}投诉,{$resultSite['site_name']}购物,{$resultSite['site_name']}介绍,{$resultSite['site_name']}怎么样,{$resultSite['site_name']}好不好,{$resultSite['site_name']}优惠信息,{$resultSite['site_name']}团购信息,{$resultSite['site_name']}网站使用,{$resultSite['site_name']}商品质量,{$resultSite['site_name']}性价比, {$resultSite['site_name']}送货,{$resultSite['site_name']}售后服务,{$resultSite['site_name']}信誉,{$resultSite['site_name']}新闻";
		//模板输出
		$this->assign('show_zhanti_menu' , 1); //左侧菜单显示专题
		$this->assign('sys_seotitle' , $seotitle);
		$this->assign('sys_seokeywords',$seokeywords);
		$this->assign('sys_seodescription' , $seodescription);
		$this->assign('bigClassId' , $bigClassId);
		$this->assign('isRl' , $isRl);
		$this->assign('leftcate' , $LeftCate);
		$this->assign('arrAlexa' , $arrAlexa);
		$this->assign('Htl' , $Htl);
		$this->assign('resultsite' , $resultSite);
		$this->assign('morePingJia' , $morePingJia);
		$this->assign('moreTouSu' , $moreTouSu);
		$this->assign('tousuamount' , $TouSuAmount);
		$this->assign('tousuclass' , $arrTouSuClass);
		$this->assign('arrcommend' , $arrCommend);
		$this->display();
	}
	
	public function zhexiantu(){
		global $_SGLOBAL;
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
		if($siteid){
			$LineData = getZheXian($siteid);
			//载入折线图处理类
			Vendor('jpgraph.jpgraph');
			Vendor('jpgraph.jpgraph_line');
			$graph = new Graph(520,200);
			$graph->SetMargin(40,40,10,30);	//左，右，上，下
			$graph->SetScale("textlin");
			$graph->SetFrame(true,'#f2f0e4',1);//
			$graph->SetMarginColor("#f2f0e4"); //折线图背景颜色
			$graph->title->SetFont(FF_SIMSUN,FS_BOLD,8); // 设置标题中文字体 
			$graph->legend->SetFont(FF_SIMSUN,FS_BOLD,6); //设置线条指示字体
			$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL,8);//设置X轴字体
			$graph->yaxis->SetFont(FF_SIMSUN,FS_NORMAL,8);//设置Y轴字体
			$graph->xgrid->Show();
			$graph->xgrid->SetLineStyle("solid");
			$graph->xgrid->SetColor('#E3E3E3');
			$graph->xaxis->SetPos('min');
			$p1 = new LinePlot($LineData['f1']);
			$p2 = new LinePlot($LineData['f2']);
			$p3 = new LinePlot($LineData['f3']);
			$p4 = new LinePlot($LineData['f4']);
			$p5 = new LinePlot($LineData['f5']);
			$p6 = new LinePlot($LineData['f6']);
			$p1->SetColor('#660099');
			$p2->SetColor('#333333');
			$p3->SetColor('#336699');
			$p4->SetColor('#669999');
			$p5->SetColor('#996666');
			$p6->SetColor('#996699');
			$graph->Add($p1);
			$graph->Add($p2);
			$graph->Add($p3);
			$graph->Add($p4);
			$graph->Add($p5);
			$graph->Add($p6);
			$graph->Stroke();
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
	}
	
	public function leidatu(){
		global $_SGLOBAL;
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
		if($siteid){
			$LeiDaData = getLeiDai($siteid);
			//载入折线图处理类
			Vendor('jpgraph.jpgraph');
			Vendor('jpgraph.jpgraph_radar');
			$graph = new RadarGraph(200,200);
			$graph->SetFrame(true,'#f2f0e4',1);//
			$graph->SetMarginColor("#f2f0e4");
			$graph->SetCenter(0.5,0.55);
			$graph->title->SetFont(FF_SIMSUN,FS_BOLD,8); // 设置标题中文字体 
			$graph->legend->SetFont(FF_SIMSUN,FS_BOLD,8); //设置线条指示字体
			$graph->axis->title->SetFont(FF_SIMSUN,FS_BOLD,8);
			$graph->SetSize(0.6);
			$graph->grid->SetColor('darkgray');
			$graph->grid->Show();
			$graph->HideTickMarks();
			
			$bigClassId = getBigClass($siteid);
			switch ($bigClassId){
				case 1:
					$sF1 = iconv("UTF-8", "gb2312","易用");
					$sF2 = iconv("UTF-8", "gb2312","质量");
					$sF3 = iconv("UTF-8", "gb2312","性价比");
					$sF4 = iconv("UTF-8", "gb2312","送货");
					$sF5 = iconv("UTF-8", "gb2312","售后");
					$sF6 = iconv("UTF-8", "gb2312","信誉");
					break;
				case 2:
					$sF1 = iconv("UTF-8", "gb2312","易用");
					$sF2 = iconv("UTF-8", "gb2312","质量");
					$sF3 = iconv("UTF-8", "gb2312","性价比");
					$sF4 = iconv("UTF-8", "gb2312","效率");
					$sF5 = iconv("UTF-8", "gb2312","满意度");
					$sF6 = iconv("UTF-8", "gb2312","信誉");
					break;
			}
			
			$nF1 = 9;
			$nF2 = 8.5;
			$nF3 = 7.5;
			$nF4 = 9.2;
			$nF5 = 7.6;
			$nF6 = 8;
			$arrTitles = array($sF1,$sF2,$sF3,$sF4,$sF5,$sF6);
			$arrRadarPlot = array($nF1,$nF2,$nF3,$nF4,$nF5,$nF6);
			$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
			$graph->SetTitles($arrTitles);
			$plot = new RadarPlot($LeiDaData['website_avg']);
			$plot->SetColor("#018f9b","lightred");
			$plot->SetFill(false);
			$plot->SetLineWeight(1);
			$plot2 = new RadarPlot($LeiDaData['class_avg']);
			$plot2->SetColor("#663366","lightred");
			$plot2->SetFill(false);
			$plot2->SetLineWeight(1);
			$graph->Add($plot);
			$graph->Add($plot2);
			$graph->Stroke();
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
	}
	
	//回头
	public function huitou(){
		global $_SGLOBAL;
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
		$ht = intval($_GET['ht']) > 0 ? 1 : 0;
		$jumpUrl =  U(APP_NAME."://Webping/website" , array('siteid' => $siteid));
		$this->assign('jumpUrl' , $jumpUrl);
		//判断用户
		if(($mserr = checkstatus('user'))){
			if($mserr['flag'] == 1){
				checkrefer($_SERVER['REQUEST_METHOD'], $jumpUrl);
				$this->assign('jumpUrl' , __APP__."/User/login");
			}
			$this->error($mserr['msg']);
		}
		if($siteid){
			$data = array(
				'ht' => $ht,
				'site_id' => $siteid,
				'user_id' => $_SGLOBAL['G_uid'],
				'ht_dt' => $_SGLOBAL['timestamp'],
				'ht_date' => date("Y-m-d H:i:s", $_SGLOBAL['timestamp']),
				'user_ip' => get_client_ip(),
			);
			$DbNbHt = M("NbHt");
			$DbSiteHt = M("SiteHt");
			//判断用户最近一次操作时间，1周内一个网站只能提交一次
			$arrNbHt = $DbNbHt->field("ht_dt")->where("site_id = $siteid and user_id = ".$_SGLOBAL['G_uid'])->order("ht_dt DESC")->limit(1)->select();
			if(($_SGLOBAL['timestamp'] - $arrNbHt[0]['ht_dt'])/3600/24 < 7){
				$this->error('对不起，1周之内您只能提交一次反馈');
			}
			//写入数据库t_nb_ht
			$DbNbHt->data($data)->add();
			//判断t_site_ht中该siteid的信息存不存在
			$arrSiteHt = $DbSiteHt->where("site_id = $siteid")->find();
			if($arrSiteHt){
				//如果在t_site_ht中存在，执行更新
				if($ht == 0){
					$DbSiteHt->setInc('ht2',"site_id = $siteid");
				}elseif($ht == 1){
					$DbSiteHt->setInc('ht1',"site_id = $siteid");
				}
			}else{
				//如果在t_site_ht中不存，对t_nb_th中该siteid的数据进行统计后插入到t_site_ht
				$ht1 = $DbNbHt->where("site_id = $siteid and ht = 1")->count();
				$ht2 = $DbNbHt->where("site_id = $siteid and ht = 0")->count();
				$data = array(
					'site_id' => $siteid,
					'ht1' => $ht1,
					'ht2' => $ht2
				);
				//写入数据库
				$DbSiteHt->data($data)->add();
			}
			$this->success("您已经成功提交反馈信息");
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
	}
	
//	//评分
//	public function pingfen(){
//		global $_SGLOBAL;
//		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : 0;
//		$jumpUrl =  U(APP_NAME."://Webping/website" , array('siteid' => $siteid));
//		$this->assign('jumpUrl' , $jumpUrl);
//		$DbSite = M("NbSite");
//		$arrSite = $DbSite->field("class_id")->where("site_id = $siteid")->find();
//		//判断用户
//		if(($mserr = checkstatus('user'))){
//			$this->error($mserr['msg']);
//		}
//		if($siteid){
//			if(!$_POST){
//				$this->error("非法操作！");
//			}
//			$data = $_POST;
//			$data['f7'] = round(($data['f1'] + $data['f2'] + $data['f3'] + $data['f4'] + $data['f5'] + $data['f6'])/6);
//			$data['user_id'] = $_SGLOBAL['G_uid'];
//			$data['site_id'] = $siteid;
//			$data['class_id'] = $arrSite['class_id'];
//			$data['fdt'] = $_SGLOBAL['timestamp'];
//			$data['fdate'] = date("Y-m-d H:i:s", $_SGLOBAL['timestamp']);
//			$data['user_ip'] = get_client_ip();
//			
//			//全部评分为1或10不记录
//			if($data['f7'] == 1 || $data['f7'] == 10){
//				$this->success("感谢您参与对该网站的评分");
//			}
//			
//			$DbNbF = M("NbF");
//			$DbClassF = M("ClassF");
//			
//			//判断用户最近一次操作时间，1周内一个网站只能提交一次
//			$arrNbFNew = $DbNbF->field("fdt")->where("site_id = $siteid and user_id = ".$_SGLOBAL['G_uid'])->order("fdt DESC")->limit(1)->select();
//			if(($_SGLOBAL['timestamp'] - $arrNbFNew[0]['fdt'])/3600/24 < 7){
//				$this->error('对不起，1周之内您只能提交一次反馈');
//			}
//			
//			//写入数据库t_nb_f
//			$DbNbF->data($data)->add();
//
//			//获取当前siteid下的f1至f7的平均值
//			$arrNbF = $DbNbF->field("f1 , f2 , f3 , f4 , f5 , f6 , f7")->where("site_id = $siteid")->select();
//			$count = count($arrNbF);
//			if($arrNbF){
//				foreach ($arrNbF as $key => $value){
//					$avgf1 += $arrNbF[$key]['f1'];
//					$avgf2 += $arrNbF[$key]['f2'];
//					$avgf3 += $arrNbF[$key]['f3'];
//					$avgf4 += $arrNbF[$key]['f4'];
//					$avgf5 += $arrNbF[$key]['f5'];
//					$avgf6 += $arrNbF[$key]['f6'];
//					$avgf7 += $arrNbF[$key]['f7'];
//				}
//				$avgf1 = round($avgf1/$count);
//				$avgf2 = round($avgf2/$count);
//				$avgf3 = round($avgf3/$count);
//				$avgf4 = round($avgf4/$count);
//				$avgf5 = round($avgf5/$count);
//				$avgf6 = round($avgf6/$count);
//				$avgf7 = round($avgf7/$count);
//			}
//			
//			//更新t_nb_site表中的数据
//			$dataF = array(
//				'f1' => $avgf1,
//				'f2' => $avgf2,
//				'f3' => $avgf3,
//				'f4' => $avgf4,
//				'f5' => $avgf5,
//				'f6' => $avgf6,
//				'f7' => $avgf7,
//				'user_number' => $count,
//			);
//			$DbSite->where("site_id = $siteid")->data($dataF)->save();
//			
//			//获取当前site所在classid下的得分
//			$arrClassF = $DbClassF->where("class_id = ".$arrSite['class_id'])->find();
//			if($arrClassF){
//				//获取当前classid下的f1至f7的平均值
//				$arrClassNbF = $DbNbF->field("f1 , f2 , f3 , f4 , f5 , f6 , f7")->where("class_id = ".$arrSite['class_id'])->select();
//				$classcount = count($arrClassNbF);
//				if($arrClassNbF){
//					foreach ($arrClassNbF as $key => $value){
//						$classavgf1 += $arrClassNbF[$key]['f1'];
//						$classavgf2 += $arrClassNbF[$key]['f2'];
//						$classavgf3 += $arrClassNbF[$key]['f3'];
//						$classavgf4 += $arrClassNbF[$key]['f4'];
//						$classavgf5 += $arrClassNbF[$key]['f5'];
//						$classavgf6 += $arrClassNbF[$key]['f6'];
//						$classavgf7 += $arrClassNbF[$key]['f7'];
//					}
//					$classavgf1 = round($classavgf1/$classcount);
//					$classavgf2 = round($classavgf2/$classcount);
//					$classavgf3 = round($classavgf3/$classcount);
//					$classavgf4 = round($classavgf4/$classcount);
//					$classavgf5 = round($classavgf5/$classcount);
//					$classavgf6 = round($classavgf6/$classcount);
//					$classavgf7 = round($classavgf7/$classcount);
//				}
//				$dataClassF = array(
//					'f1_max' => $data['f1'] > $arrClassF['f1_max'] ? $data['f1'] : $arrClassF['f1_max'],
//					'f1_avg' => $classavgf1,
//					'f1_min' => $data['f1'] < $arrClassF['f1_min'] ? $data['f1'] : $arrClassF['f1_min'],
//					
//					'f2_max' => $data['f2'] > $arrClassF['f2_max'] ? $data['f2'] : $arrClassF['f2_max'],
//					'f2_avg' => $classavgf2,
//					'f2_min' => $data['f2'] < $arrClassF['f2_min'] ? $data['f2'] : $arrClassF['f2_min'],
//					
//					'f3_max' => $data['f3'] > $arrClassF['f3_max'] ? $data['f3'] : $arrClassF['f3_max'],
//					'f3_avg' => $classavgf3,
//					'f3_min' => $data['f3'] < $arrClassF['f3_min'] ? $data['f3'] : $arrClassF['f3_min'],
//					
//					'f4_max' => $data['f4'] > $arrClassF['f4_max'] ? $data['f4'] : $arrClassF['f4_max'],
//					'f4_avg' => $classavgf4,
//					'f4_min' => $data['f4'] < $arrClassF['f5_min'] ? $data['f4'] : $arrClassF['f4_min'],
//					
//					'f5_max' => $data['f5'] > $arrClassF['f5_max'] ? $data['f5'] : $arrClassF['f5_max'],
//					'f5_avg' => $classavgf5,
//					'f5_min' => $data['f5'] < $arrClassF['f5_min'] ? $data['f5'] : $arrClassF['f5_min'],
//					
//					'f6_max' => $data['f6'] > $arrClassF['f6_max'] ? $data['f6'] : $arrClassF['f6_max'],
//					'f6_avg' => $classavgf6,
//					'f6_min' => $data['f6'] < $arrClassF['f6_min'] ? $data['f6'] : $arrClassF['f6_min'],
//					
//					'f7_max' => $data['f7'] > $arrClassF['f7_max'] ? $data['f7'] : $arrClassF['f7_max'],
//					'f7_avg' => $classavgf7,
//					'f7_min' => $data['f7'] < $arrClassF['f7_min'] ? $data['f7'] : $arrClassF['f7_min'],
//					
//					'f_number' => $classcount,
//					
//					'f_dt' => $_SGLOBAL['timestamp']
//				);
//				//更新数据库t_class_f
//				$DbClassF->where("class_id = ".$arrSite['class_id'])->data($dataClassF)->save();
//			}else{
//				$dataClassF = array(
//					'f1_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f1')),
//					'f1_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f1')),
//					'f1_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f1')),
//					
//					'f2_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f2')),
//					'f2_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f2')),
//					'f2_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f2')),
//					
//					'f3_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f3')),
//					'f3_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f3')),
//					'f3_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f3')),
//					
//					'f4_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f4')),
//					'f4_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f4')),
//					'f4_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f4')),
//					
//					'f5_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f5')),
//					'f5_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f5')),
//					'f5_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f5')),
//					
//					'f6_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f6')),
//					'f6_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f6')),
//					'f6_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f6')),
//					
//					'f7_max' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->max('f7')),
//					'f7_avg' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->avg('f7')),
//					'f7_min' => round($DbNbF->where("class_id = ".$arrSite['class_id'])->min('f7')),
//					
//					'f_number' => $DbNbF->where("class_id = ".$arrSite['class_id'])->count(),
//					'f_dt' => $_SGLOBAL['timestamp'],
//				);
//				//写入数据库t_class_f
//				$DbClassF->data($dataClassF)->add();
//			}
//			$this->success("感谢您参与对该网站的评分");
//		}else{
//			$this->error('您查看的信息不存在或已经删除');
//		}
//	}
	
	//评分
	public function pingfen(){
		global $_SGLOBAL;
		$siteid = empty($_GET['siteid']) ? 0 : intval($_GET['siteid']);
		$jumpUrl =  U(APP_NAME."://Webping/website" , array('siteid' => $siteid));
		$this->assign('jumpUrl' , $jumpUrl);
		$DbSite = M("NbSite");
		$arrSite = $DbSite->where("site_id = $siteid")->find();
		//判断用户
		if(($mserr = checkstatus('user'))){
			if($mserr['flag'] == 1){
				checkrefer($_SERVER['REQUEST_METHOD'], $jumpUrl);
				$this->assign('jumpUrl' , __APP__."/User/login");
			}
			$this->error($mserr['msg']);
		}
		if($siteid){
			if(!$_POST){
				$this->error("非法操作！");
			}
			$data = $_POST;
			$data['f7'] = round(($data['f1'] + $data['f2'] + $data['f3'] + $data['f4'] + $data['f5'] + $data['f6'])/6);
			$data['user_id'] = $_SGLOBAL['G_uid'];
			$data['site_id'] = $siteid;
			$data['class_id'] = $arrSite['class_id'];
			$data['fdt'] = $_SGLOBAL['timestamp'];
			$data['fdate'] = date("Y-m-d H:i:s", $_SGLOBAL['timestamp']);
			$data['user_ip'] = get_client_ip();
			
			//全部评分为1或10不记录
			if($data['f7'] == 1 || $data['f7'] == 10){
				$this->success("感谢您参与对该网站的评分");
			}
			
			$DbNbF = M("NbF");
			$DbClassF = M("ClassF");
			
			//判断用户最近一次操作时间，1周内一个网站只能提交一次
			$arrNbFNew = $DbNbF->field("fdt")->where("site_id = $siteid and user_id = ".$_SGLOBAL['G_uid'])->order("fdt DESC")->limit(1)->select();
			if(($_SGLOBAL['timestamp'] - $arrNbFNew[0]['fdt'])/3600/24 < 7){
				$this->error('对不起，1周之内您只能提交一次反馈');
			}
			
			//写入数据库t_nb_f
			$DbNbF->data($data)->add();
		
			//更新t_nb_site表中的数据
			$dataF = array(
				'f1' => ($arrSite['f1'] * $arrSite['user_number'] + $data['f1']) / ($arrSite['user_number'] + 1),
				'f2' => ($arrSite['f2'] * $arrSite['user_number'] + $data['f2']) / ($arrSite['user_number'] + 1),
				'f3' => ($arrSite['f3'] * $arrSite['user_number'] + $data['f3']) / ($arrSite['user_number'] + 1),
				'f4' => ($arrSite['f4'] * $arrSite['user_number'] + $data['f4']) / ($arrSite['user_number'] + 1),
				'f5' => ($arrSite['f5'] * $arrSite['user_number'] + $data['f5']) / ($arrSite['user_number'] + 1),
				'f6' => ($arrSite['f6'] * $arrSite['user_number'] + $data['f6']) / ($arrSite['user_number'] + 1),
				'f7' => ($arrSite['f7'] * $arrSite['user_number'] + $data['f7']) / ($arrSite['user_number'] + 1),
				'user_number' => $arrSite['user_number'] + 1,
			);
			$DbSite->where("site_id = $siteid")->data($dataF)->save();
			
			//获取classid下的所有网站
			$arrSiteInClass = $DbSite->where("class_id = ".$arrSite['class_id']." and f1 > 0 and f2 > 0 and f3 > 0 and f4 > 0 and f5 > 0 and f6 > 0 and f7 > 0")->select();
			$countSite = count($arrSiteInClass);
			foreach ($arrSiteInClass as $key => $value){
				$arrFen['f1'][] = $value['f1'];
				$sum['f1'] = $sum['f1'] + $value['f1'];
				$arrFen['f2'][] = $value['f2'];
				$sum['f2'] = $sum['f2'] + $value['f2'];
				$arrFen['f3'][] = $value['f3'];
				$sum['f3'] = $sum['f3'] + $value['f3'];
				$arrFen['f4'][] = $value['f4'];
				$sum['f4'] = $sum['f4'] + $value['f4'];
				$arrFen['f5'][] = $value['f5'];
				$sum['f5'] = $sum['f5'] + $value['f5'];
				$arrFen['f6'][] = $value['f6'];
				$sum['f6'] = $sum['f6'] + $value['f6'];
				$arrFen['f7'][] = $value['f7'];
				$sum['f7'] = $sum['f7'] + $value['f7'];
			}

			for($i = 1; $i <= 7; $i++){
				$min['f'.$i] = min($arrFen['f'.$i]);
				$max['f'.$i] = max($arrFen['f'.$i]);
				$avg['f'.$i] = $sum['f'.$i] / $countSite;
			}

			$dataClassF = array(
				'f1_max' => $max['f1'],
				'f1_avg' => $avg['f1'],
				'f1_min' => $min['f1'],
					
				'f2_max' => $max['f2'],
				'f2_avg' => $avg['f2'],
				'f2_min' => $min['f2'],
				
				'f3_max' => $max['f3'],
				'f3_avg' => $avg['f3'],
				'f3_min' => $min['f3'],
				
				'f4_max' => $max['f4'],
				'f4_avg' => $avg['f4'],
				'f4_min' => $min['f4'],
				
				'f5_max' => $max['f5'],
				'f5_avg' => $avg['f5'],
				'f5_min' => $min['f5'],
				
				'f6_max' => $max['f6'],
				'f6_avg' => $avg['f6'],
				'f6_min' => $min['f6'],
				
				'f7_max' => $max['f7'],
				'f7_avg' => $avg['f7'],
				'f7_min' => $min['f7'],
					
				'f_number' => $countSite,
					
				'f_dt' => $_SGLOBAL['timestamp']
			);
			//更新数据库t_class_f
			$DbClassF->where("class_id = ".$arrSite['class_id'])->data($dataClassF)->save();
			$this->success("感谢您参与对该网站的评分");
		}else{
			$this->error('您查看的信息不存在或已经删除');
		}
	}
}
?>
